package cn.hy.hot100;

class Solution_3 {
    public int lengthOfLongestSubstring(String s) {
        if (s.isEmpty()) {
            return 0;
        }
        char[] freq = new char[128];
        int left = 0, right = 0;
        int n = s.length();
        int ans = 0;
        while (right < n) {
            char c = s.charAt(right);
            freq[c]++;
            right++;
            while (freq[c] > 1) {
                char d = s.charAt(left);
                freq[d]--;
                left++;
            }
            // 先执行的 right ++ 所有这里不需要加1
            ans = Math.max(ans, right - left);
        }
        return ans;

    }
}